#ifndef __HTTP_DOWNLOAD_H_
#define __HTTP_DOWNLOAD_H_

typedef struct {
	int file_fd;			//保存文件的 fd
	int file_dl_size;		//已下载的大小,用来断点续传
	int channel;			//channel:tcp/uart
	char url[512];			//文件下载链接
	char ip[256];			//IP或域名
	char port[256];			//端口：默认80
	char path[256];			//文件在服务器路径
	char file_name[256];	//文件名,可包含路径
	int head_buf_size;		//http头部缓存BUF大小
	int data_buf_size;		//http数据缓存BUF大小
	int file_size;			//文件总大小
	int data_start;			//HTTP包数据起始
	int data_end;			//HTTP包数据结束
	int pack_index;			//下载哪一个包
	int pack_dl_size;		//包已下载大小
	int pack_size;			//总包大小
	int is_unpacking;		//HTTP下发没有拆包
	int recv_size;			//单次收到的包大小
	char *pack_buf;			//一个包的缓存
} HTTP_DOWNLOAD_DESC;

int http_get_file_name(char *url, char *save_path, char *file_name);
HTTP_DOWNLOAD_DESC *http_download_init(char *url, char *save_path);
void http_download_exit(HTTP_DOWNLOAD_DESC *download);
void http_download_data_send(HTTP_DOWNLOAD_DESC *download);
int http_download_data_recv(HTTP_DOWNLOAD_DESC *download);
int http_download_data_parse(HTTP_DOWNLOAD_DESC *download);
void http_download_data_channel_set(HTTP_DOWNLOAD_DESC *download, int channel);
int http_tcp_download(char *url, char *save_path);

#endif //__HTTP_DOWNLOAD_H_
